#include <jni.h>
#include <string>
#include <vector>
#include <map>

#include "native_func_hook.h"
#include "../utils/str_helper.h"
#include "../utils/jni_helper.h"
#include "../dlfc/dlfcn_nougat.h"
#include "../utils/log.h"
#include "../dobby/include/dobby.h"
#include "enum_jni_static_method.h"
#include "../route_func/route_func.h"

struct hook_context_t {

};

#if defined(__arm64__) || defined(__aarch64__)
int64_t deal_all_hook_func(int64_t x0,
                           int64_t x1,
                           int64_t x2,
                           int64_t x3,
                           int64_t x4,
                           int64_t x5,
                           int64_t x6,
                           int64_t x7,
                           void *context,
                           void *stack_args) {

}

#else

uint32_t deal_all_hook_func(uint32_t r0,
                           uint32_t r1,
                           uint32_t r2,
                           uint32_t r3,
                           void *context,
                           void *stack_args) {
    native_method_info *info = static_cast<native_method_info *>(context);
    logd("method call: %s->%s args count %d", info->class_name.c_str(), info->method_name.c_str(),
         info->args_type.size());
    return route_jni_func(r0, r1, r2, r3, info->args_type.size(), stack_args, info->origin_call);
}

#endif

vector<native_method_info> static_jni_list;

void init_jni_hook(JNIEnv *env) {
    static_jni_list = enum_static_jni_func(env, "libtest.so");
    for (auto &item:static_jni_list) {
        logi("static jni class: %s method %s available %d", item.class_name.c_str(),
             item.method_name.c_str(), item.available);
        if (item.available) {
            auto shell_code = create_shellcode_hooking_func(deal_all_hook_func, (void *) &item);
            DobbyHook(item.addr, (void *) shell_code, &item.origin_call);
        }
    }
}






















